with Ada.Assertions; use Ada.Assertions;

use Ada;

with GNAT.IO;

with Text_File_Reader;


separate(Test_Website_Retrieval)

--
-- test download of URL contents into file system
--

procedure Test_Into_File
is

   --
   -- utility for reading file into string
   --

   package File_Util is new Text_File_Reader( Max_Stack_Size => Max_Download,
                                              Max_Heap_Size  => Max_Download );

   --
   -- read expected contents from existing file
   --

   Expected_File_Contents : constant String := File_Util.Read_Into_String(

         EXPECTED_CONTENTS_FILE_NAME );

begin

   --
   -- download to new file
   --

   Host_Address_Type.Delete( Host_Addr_Parm, 1,
                             Host_Address_Type.Length( Host_Addr_Parm ));

   Host_Address_Type.Append( Host_Addr_Parm, SITE );

   File_Name_Type.Append( File_Name_Parm, TEST_FILE_NAME );

   WebGet_Obj.Retrieve( Host_Address   => Host_Addr_Parm,
                        Output_Str_Arg => Empty_Output,
                        Output         => Write_To'Value("File"),
                        File_Name_Arg  => File_Name_Parm );

   --
   -- read file, compare to expected
   --

   Assert( Expected_File_Contents'Length =
           File_Util.Read_Into_String(TEST_FILE_NAME)'Length,

           "Length of " & SITE & " download to file varies from expected" );

   Assert( Expected_File_Contents = File_Util.Read_Into_String(TEST_FILE_NAME),

           SITE & " download to file varies from expected" );


end Test_Into_File;